# @Version : 1.0
# @Author  : wxz
# @File    : user_router.py
# @Time    : 2025/6/1 16:44
# @Describe: 描述...
from fastapi import APIRouter, Depends, dependencies
from sqlmodel import Session

from apps.user.schemas.user_schema import UserRegister, UserLogin
from apps.user.service.user_service import UserService
from commons.result import Result

users = APIRouter()

@users.post("/register", response_model=Result, summary="用户注册")
async def register(user_register: UserRegister, user_service: UserService = Depends()):

    user_service.register(user_register)

    return Result(message="注册成功,请跳转到登录")

@users.post("/login", response_model=Result, summary="用户登录")
async def login(user_login: UserLogin, user_service: UserService = Depends()):

    token = user_service.login(user_login)

    return Result(message="登录成功", data=token)

@users.get(path="/find/{username}", summary="根据用户名查询用户", response_model=Result)
async def find_user_by_username(username: str, user_service: UserService = Depends(UserService)):

    user_vo = user_service.find_by_username(username)

    result = Result()
    result.data = user_vo

    return result








